package com.fast.common.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fast.common.annotation.Commit;
import com.fast.common.base.mapper.IBaseMapper;
import com.fast.common.base.service.IBaseService;
import com.fast.common.util.PageQuery;
import com.fast.common.util.PageUtil;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;

/**
 * @Title：BaseService
 * @author：Administrator
 * @date：2018/7/13 15:06
 * @version：1.0
 **/
public class BaseService<M extends IBaseMapper<T>, T> extends ServiceImpl<M, T> implements IBaseService<T> {

    @Override
    public PageUtil findPage(Map<String, Object> pageQuery, QueryWrapper<T> t) {
        IPage<T> page = super.selectPage(new PageQuery<T>(pageQuery).getPage(), t);
        return new PageUtil(page.getTotal(), page.getRecords());
    }

    @Override
    @Commit
    public void delById(Serializable id) {
        String[] ids = id.toString().split(",");
        super.deleteBatchIds(Arrays.asList(ids));
    }
}
